﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace YEngineLib.Graphics
{
    public sealed class YGraphics
    {
        #region Members
        GraphicsDeviceManager   manager = null;
        YLineRenderer           lineRenderer = null;
        Texture2D               pixel = null;
        SpriteBatch             spriteBatch = null;
        #endregion

        #region Properties
        public GraphicsDeviceManager Manager
        {
            get { return manager; }
        }

        public GraphicsDevice Device
        {
            get { return manager.GraphicsDevice; }
        }

        public Viewport ScreenViewport
        {
            get { return manager.GraphicsDevice.Viewport; }
        }

        public SpriteBatch SpriteBatch
        {
            get { return spriteBatch; }
        }

        public YLineRenderer Line
        {
            get { return lineRenderer; }
        }

        public Texture2D Pixel
        {
            get { return pixel; }
        }
        #endregion

        public void Initialize(GraphicsDeviceManager graphics)
        {
            manager = graphics;
            lineRenderer = new YLineRenderer(manager.GraphicsDevice);
            pixel = new Texture2D(manager.GraphicsDevice, 1, 1);
            Color[] whitePixels = new Color[] { Color.White };
            pixel.SetData<Color>(whitePixels);

            spriteBatch = new SpriteBatch(manager.GraphicsDevice);

            manager.DeviceReset += new EventHandler<EventArgs>(ResetDevice);
        }

        public void ToggleFullScreen()
        {
            manager.IsFullScreen = !manager.IsFullScreen;

            manager.ApplyChanges();
        }

        //  Event
        private void ResetDevice(object sender, EventArgs eventargs)
        {
            lineRenderer = new YLineRenderer(manager.GraphicsDevice);

            pixel = new Texture2D(manager.GraphicsDevice, 1, 1);
            Color[] whitePixels = new Color[] { Color.White };
            pixel.SetData<Color>(whitePixels);
        }
    }
}